*******************************************************************************************
*******************************************************************************************
******************** Reclassification Risk in the Small Group Health Insurance Market
******************* by Sebastian Fleitas, Gautam Gowrisankaran and Anthony Lo Sasso 
*******************************************************************************************
*******************************************************************************************
*******************************************************************************************
******************** Table 5 Panel B and D 
*******************************************************************************************
*******************************************************************************************
*******************************************************************************************


cd "~/Dropbox/ReclassificationRisk/"
use database_individual_level.dta, replace 

 do Restat_Final_Table3_USIC.do
 do Restat_Final_Table4_EnrolleeLevel.do

****************************************************************************************************************************
preserve
****************************************************************************************************************************
*** Third Implication non FE 
set more off
*use aux_todrop_forSE.dta, clear
sort mbr_sys_id 
merge mbr_sys_id using ind_insample.dta
drop if _merge!=3
drop if year<2014
gen riskquant_dum1_aux = ( mean_pred_riskscore_rp<=1 & year==2014 & sample==1)
gen riskquant_dum2_aux = ( mean_pred_riskscore_rp>1 & year==2014 & sample==1)
bys customer_number: egen riskquant_dum1 = max(riskquant_dum1_aux)
bys customer_number: egen riskquant_dum2 = max(riskquant_dum2_aux)
gen regnonfe1 = riskquant_dum1*mean_pred_riskscore_rp
gen regnonfe2 = riskquant_dum2*mean_pred_riskscore_rp
reghdfe mean_premium  regnonfe1 regnonfe2  yeardum*  marketdum* if sample==1 , noabsorb vce(cluster customer_number)
reghdfe mean_premium  regnonfe1 regnonfe2  yeardum*  marketdum* prob_leaving if sample==1 , noabsorb vce(cluster customer_number )
reghdfe mean_premium  regnonfe1 regnonfe2  yeardum*  marketdum* prob_leaving* if sample==1 , noabsorb 
restore
****************************************************************************************************************************

****************************************************************************************************************************
*** Third Implication FE 
set more off
*use aux_todrop_forSE.dta, clear
sort mbr_sys_id
merge mbr_sys_id using ind_insample.dta
drop if _merge!=3
drop if year<2014
gen riskquant_dum1_aux = ( mean_pred_riskscore_rp<=1 & year==2014 )
gen riskquant_dum2_aux = ( mean_pred_riskscore_rp>1 & year==2014 )
bys customer_number: egen riskquant_dum1 = max(riskquant_dum1_aux)
bys customer_number: egen riskquant_dum2 = max(riskquant_dum2_aux)
xtset mbr_sys_id year
gen deltapremium =  D.mean_premium
gen laggedrisk = D.mean_pred_riskscore_rp
gen regressor1 = riskquant_dum1*laggedrisk
gen regressor2 = riskquant_dum2*laggedrisk
gen deltaprob  = D.prob_leaving
gen deltaprob2 = D.prob_leaving2
gen deltaprob3 = D.prob_leaving3
gen deltaprob4 = D.prob_leaving4
gen deltaprob5 = D.prob_leaving5
gen deltaprob6 = D.prob_leaving6
drop if year!=2015
reghdfe deltapremium   regressor1 regressor2  yeardum*              if sample==1 , noabsorb vce(cluster customer_number)
reghdfe deltapremium   regressor1 regressor2     deltaprob  if sample==1 , noabsorb vce(cluster customer_number )
reghdfe deltapremium   regressor1 regressor2     deltaprob* if sample==1 , noabsorb 
****************************************************************************************************************************
